import createRouter from './router'

const router = createRouter()

/**
 * 全局导航守卫
 * （除了全局导航守卫，还有路由独享的守卫和组件内的守卫）
 */
router.beforeEach((to, from, next) => {
  console.log('before each invoked')
  next()
})

router.beforeResolve((to, from, next) => {
  console.log('before resolve invoked')
  next()
})

router.afterEach((route) => {
  console.log('after each invoked')
  let documentTitle = '党建公众号演示'
  route.matched.forEach((path) => {
    if (path.meta.title) {
      documentTitle += ` - ${path.meta.title}`
    }
  })
  document.title = documentTitle
})

export default router

/**
 * 守卫的执行顺序：
 *
 */
